/**
 * 添加OneSIS的图层数据
 * @param {} earth 
 */
import * as Cesium from 'cesium/Cesium';
import { ImageryFactory } from "../../src"
import TilesetLayer from '../../src/layer/TilesetLayer';
import Tileset from '../../src/overlay/model/Tileset';

export default function add_onesis_layers(earth){
    // let provider = ImageryFactory.createArcGISImageryProvider();
    // earth.addBaseLayer(provider);

    //add_onesis_wms_layer(earth);

    //add_onesis_wmts_layer(earth);

    /** 3DTiles图层 */
    add_onesis_3dtiles_layer(earth)
}

/**
 * WMS图层
 * @param {} earth 
 */
function add_onesis_wms_layer(earth){
    
    add_onesis_wms_layer_dem(earth);
    //add_onesis_wms_layer_resa(earth);
}

/**
 * 添加onesis课题2的WMS服务Imagery图层
 * WMS URL地址：http://47.98.197.100:8099/onesis-service/rest/v1.0/api/layer/map/wms
 * @param {} earth 
 */
function add_onesis_wms_layer_dem(earth){

    let options = {
        url : '/onesis-service/rest/v1.0/api/layer/map/wms',
        layers : 'onesis:dem'        
    };

    let provider = ImageryFactory.createWebMapServiceImageryProvider(options);
    earth.addBaseLayer(provider);


    earth.zoomToPosition({
        lng:116, lat:39.0, alt:10000000.0
    });

}

/**
 * 添加onesis课题2的WMS服务Imagery图层
 * WMS URL地址：http://47.98.197.100:8099/onesis-service/rest/v1.0/api/layer/map/wms
 * @param {} earth 
 */
function add_onesis_wms_layer_resa(earth){

    let options = {
        url : '/onesis-service/rest/v1.0/api/layer/map/wms',
        layers : 'onesis:resa',
        format : 'image/png',
        transparent : true
    };

    let provider = ImageryFactory.createWebMapServiceImageryProvider(options);
    earth.addBaseLayer(provider);


    earth.zoomToPosition({
        lng:114.5, lat:34.5, alt:100000.0
    });
}

/**
 * WMTS图层
 */
function add_onesis_wmts_layer(earth){
    add_onesis_wmts_layer_resa_900913_png(earth);    
}

/**
 * 添加resa的WMTS图层
 * http://47.98.197.100:8099/onesis-service/rest/v1.0/api/layer/map/wmts?tilematrixset=EPSG:900913&Service=WMTS&Request=GetTile&Version=1.1.1&Format=image/png&TileMatrix=EPSG:900913:{z}&TileCol={x}&TileRow={y}&layer=onesis:网格对象测试数据1",s
 * @param {} earth 
 */
function add_onesis_wmts_layer_resa_900913_png(earth){
    let options = {
        url : '/onesis-service/rest/v1.0/api/layer/map/wmts',
        layer : 'onesis:resa',
        style : 'onesis:resa',
        format : 'image/png',
        tileMatrixSetID : 'EPSG:900913',
        tileMatrixLabels : ['EPSG:900913:0', 'EPSG:900913:1', 'EPSG:900913:2', 'EPSG:900913:3', 'EPSG:900913:4', 'EPSG:900913:5', 'EPSG:900913:6', 'EPSG:900913:7', 'EPSG:900913:8', 'EPSG:900913:9', 'EPSG:900913:10', 'EPSG:900913:11', 'EPSG:900913:12', 'EPSG:900913:13', 'EPSG:900913:14', 'EPSG:900913:15', 'EPSG:900913:16', 'EPSG:900913:17'],
        maximumLevel: 18,
    };

    let provider = ImageryFactory.createWebMapTileServiceImageryProvider(options);
    earth.addBaseLayer(provider);

    earth.zoomToPosition({
        lng:114.5, lat:34.5, alt:100000.0
    });
}

/**
 * 添加3DTiles图层
 */
function add_onesis_3dtiles_layer(earth){
    let layer = new TilesetLayer("baisha");
    earth.addLayer(layer);

    //"http://47.98.197.100:8099/onesis-service/rest/v1.0/api/oss/resource?owner=test0&path=/testUpload/3dtiles/weifang/weifang_3dtiles/tileset.json",
    let tileset = new Tileset(
        '/onesis-service/rest/v1.0/api/oss/resource?owner=test0&path=/testUpload/3dtiles/weifang/weifang_3dtiles/tileset.json',
        {
            show: true,
            backFaceCulling: true,
        }
    );
    layer.addOverlay(tileset);    
    earth.flyTo(tileset);
}
